package 力扣._2337_移动片段得到字符串;

public class Solution {
    public boolean canChange(String start, String target) {
        //从左向右匹配
        //找到t中的L或R,在找到s中的L或R
        //若s[i]!=t[j] return f
        //L,i>=j
        //R,i<=j
        int i = 0, j = 0;
        while (true) {
            while (j < start.length() && target.charAt(j) != 'L' && target.charAt(j) != 'R') j++;
            while (i < start.length() && start.charAt(i) != 'L' && start.charAt(i) != 'R') i++;
            if (j >= start.length() && i >= start.length())
                break;
            else if (j < start.length() && i >= start.length()) {
                return false;
            } else if (j >= start.length()) {
                return false;
            }
            if (target.charAt(j) != start.charAt(i))
                return false;
            else if (target.charAt(j) == 'L' && i < j)
                return false;
            else if (target.charAt(j) == 'R' && i > j)
                return false;
            i++;
            j++;
        }
        return true;
    }

    public static void main(String[] args) {
        boolean b = new Solution().canChange("_R", "R_");
        System.out.println(b);
    }
}
